<?php
if ( ! defined('BASEPATH')) exit('el acceso directo a esta página no esta permitido.');

class clientes extends ci_controller {
     function __construct()
    {
            parent::__construct();
            $this->load->model('clientes_model','client');
            $this->load->model('auxiliar_model','aux');
            $this->load->helper('qrcode_helper');
             $this->load->helper('pdf_helper');
    }
    
    function call_ciudades(){
            $codedo= $this->input->get('id');
            $this->aux->devolver_ciudades($codedo);
        }
   
    function index(){
        if($this->session->userdata('logged_in'))
        {
            //$this->load->helper('html');
            $session_data = $this->session->userdata('logged_in');
            
            //cargamos datos para la vista
            $data['menu'] = menu_ul('clientes',$session_data['tipousuario']);
            $data['title'] = "POSMobile - Clientes";
            $data['datos']=$this->client->get_clientes($session_data['empresa']);
            $data['estados']=$this->aux->devolver_estados();
            
            //cargamos la vista clientes
            $this->load->view('partials/header',$data);
            $this->load->view('pages/clientes_view',$data);
            $this->load->view('partials/modal_clientes',$data);
            $this->load->view('partials/footer');
        }else redirect('login');
    } 
    
    function baja_clientes(){
        if($this->session->userdata('logged_in'))
        {
            $ids= json_decode($this->input->get('id'));
            $result = $this->client->eliminar($ids);
            echo $result;
        }else redirect('login');
    }
    
    function req_cliente(){
        if($this->session->userdata('logged_in'))
        {
            $ids= json_decode($this->input->get('id'));
            $this->client->get_cliente($ids);
        }else redirect('login');
    }

    function agregar(){
        if($this->session->userdata('logged_in'))
        {
            $session_data = $this->session->userdata('logged_in');
            $nuevo_cliente = array(
                'nombre'=> strtoupper($this->input->post('nombre')),
                'rfc'=>  strtoupper($this->input->post('rfc')),
                'domicilio' => strtoupper($this->input->post('domicilio')),
                'estado' =>  $this->input->post('estado'),
                'ciudad'=>   $this->input->post('ciudad'),
                'contacto'=> strtoupper($this->input->post('contacto')),
                'telefono'=> $this->input->post('telefono'),
                'carpetaimagenes' => strtoupper("/".$this->input->post('carpeta')."/"),
                'empresa' => $session_data['empresa'],
                'email'   => strtolower($this->input->post('email')),
                'latitude' => $this->input->post('latitude'),
                'longitude' => $this->input->post('longitude'),
                'activo' => 1);
            $rows = $this->client->agrega_cliente($nuevo_cliente);
            echo json_encode(array('rows'=>$rows));
        }else redirect('login');
     }    
    
    function modificar(){
        if($this->session->userdata('logged_in'))
            {
                $session_data = $this->session->userdata('logged_in');
                $datos_cliente = array(
                    'domicilio' => strtoupper($this->input->post('domicilio')),
                    'estado' =>  $this->input->post('estado'),
                    'ciudad'=>   $this->input->post('ciudad'),
                    'contacto'=> strtoupper($this->input->post('contacto')),
                    'telefono'=> $this->input->post('telefono'),
                    'empresa' => $session_data['empresa'],
                    'email'   => strtolower($this->input->post('email')),
                    'latitude' => $this->input->post('latitude'),
                    'longitude' => $this->input->post('longitude'),
                    'activo' => 1);
                $result = $this->client->update_cliente($this->input->post('hiddenid'),$datos_cliente);
                echo json_encode(array('rows'=>$result));
            }else redirect('login');
    }
    
    
    
    public function  generarcodigoqr($id) {
        qrcode();        
        qrcode::png($id,'uploads/007_4.png', qr_eclevel_l,5); 
       // echo '<img src="http://localhost:8080/posmobile/uploads/007_4.png" />'; 
        
        
        
 tcpdf();
$pdf = new tcpdf(pdf_page_orientation, pdf_unit, pdf_page_format, true, 'utf-8', false);
$title="";
$subtitle="
               <a></a>              
";

$pdf->setheaderdata('', pdf_header_logo_width, $title, $subtitle);
// set header and footer fonts
$pdf->setheaderfont(array(pdf_font_name_main, '', 9));
$pdf->setfooterfont(array(pdf_font_name_data, '', pdf_font_size_data));
// set default monospaced font
$pdf->setdefaultmonospacedfont(pdf_font_monospaced);
// set margins
$pdf->setmargins(pdf_margin_left, pdf_margin_top, pdf_margin_right);
$pdf->setheadermargin(pdf_margin_header);
$pdf->setfootermargin(pdf_margin_footer);
// set auto page breaks
$pdf->setautopagebreak(true, pdf_margin_bottom);
// set image scale factor
$pdf->setimagescale(pdf_image_scale_ratio);
$pdf->setfont('times', '', 7);
$pdf->addpage();
$pdf->setxy(32, 70);
$pdf->image(base_url().'uploads/007_4.png', '', '', 150, 150, '', '', 't', false, 300, '', false, false, 1, false, false, false);
$pdf->lastpage();
$pdf->output('fdfd.pdf', 'i');
        
    }
        
}

/* end of file clientes.php */
/* location: ./application/controllers/clientes.php */